package edu.washington.ling.syntric.struct.error;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

public class PrintingExceptionHandler {
	public void handle(Exception e, String message) {
		handle(e, message, System.err);
	}
	public void handle(Exception e, String message, PrintStream toStream) {
		String error = String.format("Error: %s", message);
		String details = String.format("Details: %s", e.getMessage());
		try {
			PrintStream err = new PrintStream(toStream, true, "UTF-8");
			err.println(error);
			err.println(details);
			err.println();
		}
		catch (UnsupportedEncodingException uee) {
			toStream.print(error);
			toStream.print(details);
			toStream.println("(error is not UTF-8 due to unsupported encoding)");
		}
	}

}
